import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ty_smart_watch/common/images_url.dart';
import 'package:ty_smart_watch/db/device_in_db_controller.dart';
import 'package:ty_smart_watch/page/watchdetail/body_grid.dart';
import 'package:ty_smart_watch/page/watchdetail/setting_list.dart';
import 'package:ty_smart_watch/page/watchdetail/watch_detail.dart';

import '../../utils/Log.dart';

class WatchDetailPage extends StatefulWidget {
  const WatchDetailPage({super.key});

  @override
  State<StatefulWidget> createState() => _WatchDetailPage();
}

class _WatchDetailPage extends State<WatchDetailPage> {
  String mac = "";
  String deviceName = "";
  DeviceInDbController dbController = Get.find();

  @override
  void initState() {
    super.initState();
    mac = Get.arguments["mac"];
    Log.d("页面收到的数据：$mac");

    var device = dbController.deviceList.value.firstWhere((device) => device["address"] == mac);
    Log.d("device : $device");
    deviceName = device["name"];
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(/*"设备名称"*/ deviceName),
        centerTitle: true,
        leading: IconButton(
          icon: const Icon(Icons.arrow_back_ios),
          onPressed: () {
            Get.back();
          },
        ),
        actions: [
          IconButton(
              onPressed: () {
                Log.d("编辑设备名称");
              },
              icon: Image.asset(ICON_EDIt, width: 20, height: 20))
        ],
      ),
      body: Column(
        children: [
          WatchDetail(mac: mac),
          const SizedBox(height: 10),
          BodyGrid(mac: mac),
          SettingList(mac: mac)
        ],
      ),
    );
  }
}
